<link href="<?php echo CSS_User_URL; ?> /Article_List_style.css" rel="stylesheet" type="text/css"> 
<script src="<?php echo JS_User_URL; ?>/Article_Post_js.js" type="text/javascript"></script>
<section id="main_cover" class="cover center-child">
    <div class="cover_intro">
        <div id="someone_image" class="center-child image_parent">
            <img src="<?php echo Yii::app()->baseUrl; ?>/images/People_demo.jpg" alt="Ideawebsite.com">
        </div>
        <div id="someone_things">
            <h1 class="someone_slogan">Always do the best</h1>
            <span class="someone_owner"><a href="#">Adam Kenisa</a></span>
        </div>

    </div>
</section>


<div class="home_wrapper">

    <div id="function_bar">

        <div id="sort_bar2" class="function_bar">
            <select class="sort_list button_base" id="search-target" name="target">
                <option value="all">Tìm Tất cả</option>
                <option value="title">Tiêu đề</option>
                <option value="author">Tác giả</option>
            </select>
        </div>
        <div id="sort_bar2" class="function_bar">
            <select class="sort_list button_base" id="search-sort" name="target">
                <option value="time">Thời gian đăng</option>
                <option value="view">Lượt xem</option>
                <option value="share">Lượt chia sẻ</option>
                <option value="creative">Tính sáng tạo</option>
            </select>
        </div>
        <div id="search_bar" class="function_bar">
            <form class="search_form">
                <input id="search-content" name="content" class="search_value" type="text" placeholder="Tìm kiếm">
                <button class="button_base" id="btnSearchArticle"><span>☌</span></button>
                <!--<a id="btn-timkiem" href="javascript:void(0)" class="button_base"><span>☌</span></a>-->
            </form>
        </div>
        
    </div>
    <?php
//    json_decode($)
    ?>
    <p class="message-result-search" style="display: none;">Không tìm thấy kết quả nào.</p>
    <div id="article_area">
        <div class="large_article">
            <div class="image_article image_parent">
                <a href="<?php echo Yii::app()->createUrl('User/ArticleDetails', array('Id' => $First_Id)); ?>"><img src="<?php echo Yii::app()->baseUrl . '/images/ArticleCover/' . $First_AnhBia; ?>"></a>
            </div>

            <div class="article_details">
                <div class="article_imfomation">
                    <div class="basic_imfarmation">
                        <div class="article_field center-child">
                            <!--<a class="button_base" href="#"><span>Cơ khí gia dụng</span></a>-->
                        </div>
                        <div class="article_time center-child">
                            <span>
                                <?php echo date('d-m-Y H:m:s', strtotime($First_NgayDang)); ?>
                            </span>
                        </div>
                    </div>
                </div>
                <div class="article_title">
                    <a href="<?php echo Yii::app()->createUrl('User/ArticleDetails', array('Id' => $First_Id)); ?>"><span><?php echo $First_TieuDe; ?></span></a>
                </div>

            </div>
            <div class="article_intro">
                <div class="article_analysis">
                    <div class="article_owner center-child">
                        <a href="<?php echo $First_NguoiDangURL; ?>"><h4><?php echo $First_TenNguoiDang; ?></h4></a>
                    </div>
                    <div class="analysis_information">
                        <div class="analysis_view center-child">
                            <img src="<?php echo Yii::app()->baseUrl; ?>/images/Icons/View-light.png" class="icon_48">
                            <span><?php echo $First_LuotXem; ?></span>
                        </div>
                        <div class="analysis_feedback center-child">
                            <img src="<?php echo Yii::app()->baseUrl; ?>/images/Icons/Note-light.png" class="icon_48">
                            <span><?php echo $First_LuotChiaSe; ?></span>
                        </div>
                        <div class="analysis_creative center-child">
                            <img src="<?php echo Yii::app()->baseUrl; ?>/images/Icons/Idea-light.png" class="icon_48">
                            <span><?php echo $First_DiemSangTao; ?></span>
                        </div>
                    </div>
                </div>
                <div class="article_intro_content">
                    <article>
                        <?php echo $First_GioiThieu; ?>
                    </article>
                </div>
            </div>

        </div>

        <div class="field_list">
            <UL id="field_tree">
                <?php
                foreach ($LinhVuc as $LV) {
                    echo '<LI><span>' . $LV->Ten . '</span><UL>';
                    foreach ($DanhMuc as $DM) {
                        if ($DM->LinhVucId == $LV->Id) {
                            echo '<LI class="article_field" data-id="' . $DM->Id . '"><span>' . $DM->Ten . '</span><span class="choosen_status"></span></LI>';
                        }
                    }
                    echo '</UL></LI>';
                }
                ?>
            </UL>
        </div>
    </div>

    <div class="other_article">   
        <?php echo $YTuongs; ?>        
    </div>
    <div class="pages_bar">
        <a href="#" class="first_page"></a>
        <a href="#" class="privious_page"></a>
        <a href="#" class="current_page active_page"></a>
        <a href="#" class="next_page"></a>
        <a href="#" class="last_page"></a>
    </div>
</div>
<script>
    function getSlogan() {
        $.get('<?php echo Yii::app()->createUrl('User/GetSlogan'); ?>', {}, function(data) {
            if (data !== null) {
                $('.cover_intro div img').attr('src', '<?php echo Yii::app()->baseUrl; ?>/images/ProfileImage/' + data['Avatar']);
                $('.cover_intro div .someone_slogan').html(data['Slogan']);
                $('.cover_intro div .someone_owner a').attr('href', '<?php echo Yii::app()->createUrl('User/'); ?>' + data['Id']);
                $('.cover_intro div .someone_owner a').html(data['BiDanh']);
            }
        }, 'json');
    }
    function fillResultSearch(data) {
        if (data['Quantity'] === 0) {
//            $('#count-result').html(0);
            $('#article_area').hide();
            $('.other_article').html('');
            $('.message-result-search').show();
        } else {
            $('.other_article').html(data['YTuongs']);
            $('.large_article .image_article a').attr('href', data['First_ArticleURL']);
            $('.large_article .image_article a img').attr('src', data['First_AnhBiaURL']);
            $('.large_article .article_time span').html(data['First_NgayDang']);
            $('.large_article .article_title a').attr('href', data['First_ArticleURL']);
            $('.large_article .article_title a span').html(data['First_TieuDe']);
            $('.large_article .article_owner a h4').html(data['First_TenNguoiDang']);
            $('.large_article .analysis_feedback span').html(data['First_LuotChiaSe']);
            $('.large_article .analysis_creative span').html(data['First_DiemSangTao']);
            $('.large_article .analysis_view span').html(data['First_LuotXem']);
//            $('#count-result').html(data['Quantity']);
            $('#article_area').show();
            $('.message-result-search').hide();
        }
    }
    $(document).ready(function() {
        getSlogan();
        setInterval(function() {
            getSlogan();
        }, 10000);
        $('.article_field').click(function() {
            $('.other_article').html('');
            var DanhMucs = [];
            $.each($('.article_field.field_choosen'), function() {
                DanhMucs.push($(this).attr('data-id'));
            });
            URL = '<?php echo Yii::app()->createUrl('User/ArticleFilter'); ?>';
            $.post(URL, {Filter: 'DANHMUC', data: DanhMucs}, function(result) {
                var data = JSON.parse(result);
                fillResultSearch(data);
            });
        });
        $('#btnSearchArticle').click(function(e) {
            e.preventDefault();
            var content = $('#search-content').val();
            var target = $('#search-target').val();
            var sort = $('#search-sort').val();
            URL = '<?php echo Yii::app()->createUrl('User/SearchArticle'); ?>';
            $.post(URL, {content: content, target: target, sort: sort}, function(result) {
                var data = JSON.parse(result);
                fillResultSearch(data);
            });
        });
    });
</script>